import { AccountResponse, DailyResponse, LeaderboardResponse, TipResponse } from "./model/model-account";
import { AnswerResponse, QuestionResponse, SettleResponse, StartGameResponse } from "./model/model-game";
import GCNetwork from "./network/GCNetwork";


export const enum GameMode {
    CLASSIC = 0,
    TIMELIMITED = 1,
    SURVIVAL = 2
}

export default class GCConnection {

    static async requestTip(start = 0): Promise<TipResponse> {
        return GCNetwork.POST('quiz/utils/tip', { start }, TipResponse);
    }

    static async requestLeaderboard(): Promise<LeaderboardResponse> {
        return GCNetwork.POST('quiz/utils/board', {}, LeaderboardResponse);
    }

    static async requestDailyReward(): Promise<DailyResponse> {
        return GCNetwork.POST('quiz/utils/daily-reward', {}, DailyResponse);
    }

    static async settleGame(): Promise<SettleResponse> {
        return GCNetwork.POST('quiz/settle-game', {}, SettleResponse);
    }

    static async requestAnswer(id: number, answer: string): Promise<AnswerResponse> {
        return GCNetwork.POST('quiz/answer', { id, answer }, AnswerResponse);
    }

    static async requestQuestion(lastId: number): Promise<QuestionResponse> {
        return GCNetwork.POST('quiz/question', { lastId }, QuestionResponse);
    }

    static async startGame(mode: GameMode): Promise<StartGameResponse> {
        return GCNetwork.POST('quiz/start-game', { mode }, StartGameResponse);
    }

    static async wxLogin(code: string): Promise<AccountResponse> {
        return GCNetwork.POST('user/wxlogin', { code }, AccountResponse);
    }

    static async validate(name: string) {
        return GCNetwork.GET('user/validate', { name });
    }

    static async signin(name: string, password: string) {
        return GCNetwork.POST('user/login', { name, password }, AccountResponse);
    }

    static async signup(name: string, password: string) {
        return GCNetwork.POST('user/register', { name, password }, AccountResponse);
    }

    static async userinfo() {
        return GCNetwork.POST('user/user-info', {}, AccountResponse);
    }
}

if (CC_DEBUG) {
    (window as any).GCConnection = GCConnection;
}
